#include "entity.h"
#include "geom.h"
#include "Physics.h"
#include "spherecollider.h"
#include "AABBCollider.h"

SphereCollider::SphereCollider(Entity* entity, float radius):
Collider(entity),
m_radius(radius)
{
    //ctor
}

SphereCollider::~SphereCollider()
{
    //dtor
}

bool SphereCollider::collideWith(const Collider* collider)
{
	if(collider->m_type == SPHERE){
		Vector3 entityPosition = getEntity()->getPosition();
		float entityRadius = getRadius();

		Vector3 otherPosition = collider->getEntity()->getPosition();
		float otherRadius = collider->getRadius();

		//If the distance between the 2 center points is less than the 2 radii combined
		//then this is a collision
		if ((entityPosition - otherPosition).length() <= (entityRadius + otherRadius))
		{
		   return true;
		}

		return false;
	}
	else if(collider->m_type == AABB){
		AABBCollider* c = (AABBCollider*)collider;
		Vector3 pos1 = getEntity()->getPosition();
		Vector3 pos2 = c->getEntity()->getPosition();

		float sqDist = Physics::sqDistPointToBox(pos1.x,pos1.y,pos1.z,pos2.x,pos2.y,pos2.z,c->getWidth()/2.0f,c->getHeight()/2.0f,c->getDepth()/2.0f);

		return sqDist <= getEntity()->getCollider()->getRadius() * getEntity()->getCollider()->getRadius();

	}


	return false;
}

